/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javacommunity.model.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "category_type", catalog = "db_javadanang", uniqueConstraints = {
    @UniqueConstraint(columnNames = "categoryTypeCode"),
    @UniqueConstraint(columnNames = "categoryTypeName")})
public class CategoryType implements java.io.Serializable {

    private Integer categoryTypeId;
    private String categoryTypeCode;
    private String categoryTypeName;
    private String imagePath;
    private boolean active;
    private List<Category> categories = new ArrayList<Category>();

    public CategoryType() {
    }

    public CategoryType(String categoryTypeCode, String categoryTypeName,
            String imagePath, boolean active) {
        this.categoryTypeCode = categoryTypeCode;
        this.categoryTypeName = categoryTypeName;
        this.imagePath = imagePath;
        this.active = active;
    }

    public CategoryType(String categoryTypeCode, String categoryTypeName,
            String imagePath, boolean active, List<Category> categories) {
        this.categoryTypeCode = categoryTypeCode;
        this.categoryTypeName = categoryTypeName;
        this.imagePath = imagePath;
        this.active = active;
        this.categories = categories;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "categoryTypeId", unique = true, nullable = false)
    public Integer getCategoryTypeId() {
        return this.categoryTypeId;
    }

    public void setCategoryTypeId(Integer categoryTypeId) {
        this.categoryTypeId = categoryTypeId;
    }

    @Column(name = "categoryTypeCode", unique = true, nullable = false, length = 15)
    public String getCategoryTypeCode() {
        return this.categoryTypeCode;
    }

    public void setCategoryTypeCode(String categoryTypeCode) {
        this.categoryTypeCode = categoryTypeCode;
    }

    @Column(name = "categoryTypeName", unique = true, nullable = false, length = 20)
    public String getCategoryTypeName() {
        return this.categoryTypeName;
    }

    public void setCategoryTypeName(String categoryTypeName) {
        this.categoryTypeName = categoryTypeName;
    }

    @Column(name = "imagePath", nullable = false, length = 100)
    public String getImagePath() {
        return this.imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    @Column(name = "active", nullable = false)
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "categoryType")
    @Fetch (FetchMode.SELECT)
    public List<Category> getCategories() {
        return this.categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

}
